import React from 'react';
import { Image, View, Text } from '@tarojs/components';
import { AtIcon } from 'taro-ui';
import Taro from '@tarojs/taro';
import utils from '@/utils/index'
import pSearch from '@/images/common/searchIcon.png';
import './index.scss';
import "taro-ui/dist/style/components/icon.scss";

const ModuleSearch = ({ componentCfg }) => {
  const goSearchPage = () => {
    Taro.navigateTo({ url: '/mainSubPack/searchResult/index' });
  };
  return (
    <View
      className="ModuleSearch"
      style={{
        paddingTop: componentCfg.styleSettingRender.paddingTop,
        paddingBottom: componentCfg.styleSettingRender.paddingBottom,
        background: componentCfg.styleSettingRender.backgroundColor,
      }}
    >
      <View className="searchWidget">
        <View
          className="searchWrap"
          onClick={goSearchPage}
          style={{
            justifyContent: componentCfg.styleSettingRender.justifyContent,
            borderRadius: componentCfg.styleSettingRender.borderRadius,
            background: componentCfg.styleSettingRender.backgroundColorWrap,
            borderColor: componentCfg.styleSettingRender.borderColor,
            color: componentCfg.styleSettingRender.color,
          }}
        >
          <Image className="searchIcon" src={pSearch} />
          <Text className="searchText">{componentCfg.content.searchKey}</Text>
        </View>
        <View className="wrap-handle">
          {componentCfg.content.coupon === 1 && <Image mode="widthFix" src={require('@/images/cart/to-original.png')} className='handle-icon' onClick={()=>{
            if (!utils.getToken()) {
              Taro.navigateTo({
                url: '/pages/other/login/index',
              });
              return;
            }
            Taro.navigateTo({ url: '/giftCardSubPack/myCoupon/index' });
          }} />}
          
          {componentCfg.content.cart === 1 && <Image mode="widthFix" src={require('@/images/cart/shopping-cart.png')} className='handle-icon' onClick={()=>{
            if (!utils.getToken()) {
              Taro.navigateTo({
                url: '/pages/other/login/index',
              });
              return;
            }
            Taro.navigateTo({ url: '/pages/mainPages/cartSin/index' });
          }} />}
          {componentCfg.content.order === 1 && <Image mode="widthFix" src={require('@/images/cart/document.png')} className='handle-icon' onClick={()=>{
            if (!utils.getToken()) {
              Taro.navigateTo({
                url: '/pages/other/login/index',
              });
              return;
            }
            Taro.navigateTo({
              url:'/orderSubPack/order-list/index'
            })
          }} />}
        </View>
      </View>
    </View>
  );
};

export default ModuleSearch;
